﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Simple.Admin.Application.Commands;
using Simple.Common.Application.BaseControllers;
using Simple.Common.Application.Dtos;
using Simple.Common.SignalR.Hubs;
using System.Collections.Generic;
using System.Threading.Tasks;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Admin.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AdminUserController : SimpleController
    {
        private readonly IMediator _mediator;
        private IHubContext<StronglyTypedChatHub, IChatClient> _strongChatHubContext { get; }
        public AdminUserController(IMediator mediator, IHubContext<StronglyTypedChatHub, IChatClient> strongChatHubContext)
        {
            _mediator = mediator;
            _strongChatHubContext = strongChatHubContext;
        }

        //public async Task SendMessage(string user, string message)
        //{
        //    await _strongChatHubContext.Clients.All.ReceiveMessage(user, message);
        //}
        /// <summary>
        /// 创建账号信息
        /// </summary>
        /// <param name="createAdminUserCommand"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<ResultDto<bool>> CreateAdminUser(CreateAdminUserCommand createAdminUserCommand)
        {
            var result1 = await _mediator.Send(createAdminUserCommand);
            var result = await Bus.Send(createAdminUserCommand);
            return GetResultEntity(result);
        }
        // GET: api/<AdminUserController>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/<AdminUserController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

        // PUT api/<AdminUserController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<AdminUserController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
